package com.example.saiweisi.controller.systemAdminController;

import com.example.saiweisi.common.Result;
import com.example.saiweisi.controller.request.ChefAdminRequest;
import com.example.saiweisi.model.ChefAdmin;
import com.example.saiweisi.service.interf.IChefAdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/chefadmin")
@RestController
@CrossOrigin
@Slf4j
public class ChefAdminController {
    @Autowired
    private IChefAdminService chefAdminService;
    //分页查询
    @GetMapping("/page")
    public Result page(ChefAdminRequest chefAdminRequest) {
        return Result.success(chefAdminService.page(chefAdminRequest));
    }
    //添加
    @PostMapping("/add")
    public Result addchefadmin(@RequestBody ChefAdmin chefAdmin){
        chefAdminService.addchefadmin(chefAdmin);
        return Result.success();
    }
    //删除
    @DeleteMapping("/delete{chefAdminId}")
    public Result deletechefadmin(@PathVariable Integer chefAdminId){
        System.out.println(chefAdminId);
        chefAdminService.deletechefadmin(chefAdminId);
        return Result.success();
    }
    //重置密码
    @PutMapping("/resetpassword{chefAdminId}")
    public Result resetpassword(@PathVariable Integer chefAdminId){
        chefAdminService.resetPassword(chefAdminId);
        return Result.success();
    }
    //批量删除
    @PostMapping("/deletes")
    public Result deleteschefadmin(@RequestBody List<Integer> chefAdminIds){
        chefAdminService.deleteschefadmin(chefAdminIds);
        return Result.success();
    }
    //根据id查找
    @GetMapping("/{chefAdminId}")
    public Result getById(@PathVariable Integer chefAdminId){
        ChefAdmin chefAdmin =chefAdminService.getById(chefAdminId);
        return Result.success(chefAdmin);
    }
    //修改
    @PutMapping("/update")
    public Result updatechefadmin(@RequestBody ChefAdmin chefAdmin){
        chefAdminService.updatechefadmin(chefAdmin);
        return Result.success();
    }
}
